//
//  HomeHeaderView.m
//  DoctorFAQs
//
//  Created by zjq on 17/2/9.
//  Copyright © 2017年 zjq. All rights reserved.
//

#import "HomeHeaderView.h"
#import "SDCycleScrollView.h"
@interface HomeHeaderView ()<SDCycleScrollViewDelegate>

@property (nonatomic,strong) SDCycleScrollView * cycleScrollView;
@end
@implementation HomeHeaderView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self initlizeInterface];
    }
    return self;
}

- (void)initlizeInterface {
    
    self.backgroundColor = KHColorFromRGB(0xf8f8f8);
    UIView * whiteView = [[UIView alloc] init];
    whiteView.backgroundColor = [UIColor whiteColor];
    UIView * garyView = [[UIView alloc] init];
    garyView.backgroundColor = MYGRAYCOLOR;
    UIImageView * searchImageView = [[UIImageView alloc] init];
    searchImageView.image = [UIImage imageNamed:@"icon_search"];
    UILabel * titleLabel = [[UILabel alloc] init];
    titleLabel.text = @"搜索关键字";
    titleLabel.textColor = KHColorFromRGB(0xaaaaaa);
    titleLabel.textAlignment = NSTextAlignmentLeft;
    [garyView addSubview:searchImageView];
    [garyView addSubview:titleLabel];
    [garyView addSubview:self.searchBtn];
    [whiteView addSubview:garyView];
    
    
    [self addSubview:whiteView];
    [self addSubview:self.cycleScrollView];
//    [whiteView mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.left.width.equalTo(self);
//        make.height.mas_offset(50*xsIZE);
//        make.top.equalTo(self).offset(2*ysIZE);
//    }];
//    [garyView mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.centerX.equalTo(whiteView);
//        make.height.offset(30*ysIZE);
//        make.width.offset(260*xsIZE);
//        make.top.equalTo(whiteView).offset(10*ysIZE);
//    }];
//    [searchImageView mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.centerY .equalTo (garyView);
//        make.left.equalTo (garyView).offset(5*xsIZE);
//        make.height.equalTo (garyView).multipliedBy(0.6);
//        make.width.equalTo(searchImageView.mas_height);
//    }];
//    [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.left.equalTo(searchImageView.mas_right).offset(10*xsIZE);
//        make.height.equalTo(garyView).multipliedBy(0.8);
//        make.centerY.equalTo(garyView);
//        make.right.equalTo(garyView);
//    }];
//    [self.searchBtn mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.centerX.equalTo(garyView);
//        make.width.equalTo(garyView);
//        make.height.equalTo(garyView);
//        make.top.equalTo(whiteView).offset(2*ysIZE);
//    }];
    [self.cycleScrollView mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.left.equalTo(self);
//        make.width.equalTo(self);
//        make.bottom.equalTo(self);
//        make.top.equalTo(whiteView.mas_bottom).offset(10*ysIZE);
        make.edges.equalTo(self);
    }];
    
}


//选中图片的协议回调
- (void)cycleScrollView:(SDCycleScrollView *)cycleScrollView didSelectItemAtIndex:(NSInteger)index {
    if (self.homeHeaderDelagate &&[self.homeHeaderDelagate conformsToProtocol:@protocol(homeHeaderViewDelegate) ]) {
        [self.homeHeaderDelagate intoAVControllerWithIndex:index];
    }
}

- (void)setModelArray:(NSMutableArray<ZHomeHeaderMoedel *> *)modelArray {
    _modelArray = modelArray;
    NSMutableArray * imageArray = [@[] mutableCopy];
    for (ZHomeHeaderMoedel * model in modelArray ) {
        NSString * url = [NSString stringWithFormat:@"%@%@",IconURL,model.cover];
        [imageArray addObject:url];
    }
    _cycleScrollView.imageURLStringsGroup = imageArray;
}
//lazy
- (SDCycleScrollView *)cycleScrollView {
    if (_cycleScrollView) {
        return _cycleScrollView;
    }
    _cycleScrollView = [[SDCycleScrollView alloc] init];
    _cycleScrollView.bannerImageViewContentMode = UIViewContentModeScaleToFill;
    _cycleScrollView.pageControlAliment = SDCycleScrollViewPageContolAlimentCenter;
    _cycleScrollView.showPageControl = YES ;
    _cycleScrollView.currentPageDotColor = [UIColor grayColor];
    _cycleScrollView.currentPageDotColor = [UIColor whiteColor];
    _cycleScrollView.autoScrollTimeInterval = 1.5f;
    _cycleScrollView.delegate = self;
    return _cycleScrollView;
}
- (UIButton *)searchBtn {
    if (_searchBtn) {
        return _searchBtn;
    }
    _searchBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    
    return _searchBtn;
}

@end
